<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="./css/style.css"/>
<script type="text/javascript" src="./jquery-2.1.1.min.js"></script>

</head>
<body>
<?php 
include 'db.conf.php';
$sqlConnect = new mysqli($sServer,$sUser,$sPassword,$sDatabaseName);
$sqlConnect->query("SET NAMES 'UTF8'");

$sCourseName = '2014_w_cal';
$sTeamworkName='tw_00';

if ((isset($_REQUEST["type"])) AND ($_REQUEST["type"]=="fix"))
{	
	$aFixData = array();
	foreach ($aFixData as $sStudentNumber=>$sTeamworkScore)
	{
		$sQuery = "update `$sCourseName` set `$sTeamworkName`=".(10-$sTeamworkScore)." where `student_number` = $sStudentNumber";
		//echo $sQuery."<br/>";
		$sqlConnect->query($sQuery);
		if ($sqlConnect->affected_rows>0)
		{
			echo "updated ".$sStudentNumber." teamwork to: ".(10-$sTeamworkScore)."<br/>";
		}
		
	}die("<a href=\"inputTeamworkScore.php\">again</a>");
}
if ((isset($_REQUEST["type"])) AND ($_REQUEST["type"]=="updateTeamwork"))
{
	echo "<h1>updating $sTeamworkName</h1>";
	foreach ($_REQUEST as $sStudentNumber => $sTeamworkScore)
	{
		$sQuery = "update `".$sCourseName."` set `".$sTeamworkName."`=".$sTeamworkScore." where `student_number`=".$sStudentNumber;
		$sqlConnect->query($sQuery);
		if ($sqlConnect->affected_rows>0)
		{
			echo "updated ".$sStudentNumber." teamwork to: ".$sTeamworkScore."<br/>";
		}
	}
	echo "<a href=\"inputTeamworkScore.php\">again</a>";
} 
else 
{
	echo "<h1>$sTeamworkName</h1>";
	echo '<form method="POST" action="inputTeamworkScore.php?type=updateTeamwork">';
	for ($nTeam=1;$nTeam<21;$nTeam++)
	{	
		echo "<h1>Team $nTeam</h1>";
		$sQuery = "select `name`,`student_number`,`team` from `$sCourseName` where `team`=$nTeam order by `team`,`name` asc";
		$sqlResult = $sqlConnect->query($sQuery);
		
		while ($aStudentData = $sqlResult->fetch_array(MYSQLI_ASSOC))
		{
			echo ($aStudentData["name"].": <input class=\"score\" type =\"text\" name=\"".$aStudentData["student_number"]."\" value=\"10\"/>\r\n");
		}
	}
	echo '<button type="submit">update</button></form>';
}	
$sqlConnect->close();
?>
</body>
</html>
